#include "kukaseamtechonlasersensorinstance.h"
#include "_Interface/_global_datastruct.h"
#include "_Interface/_interface_backend.h"
#include "_Interface/_interface_hmi.h"
#include "Backend/backinstance.h"
#include "Hmi/hmiinstance.h"

KUKASeamTechonLaserSensorInstance::KUKASeamTechonLaserSensorInstance(short Local_Remote){
    if(Local_Remote == REMOTEHMI){
        this->pHmi = new HmiInstance(REMOTEHMI);
    }
    else if(Local_Remote == LOCALCONTOLLER) {
        this->pBackend = new backinstance();
        this->pHmi = new HmiInstance(LOCALCONTOLLER);
        this->RegisiterBackendtoHmi();
    }
}
KUKASeamTechonLaserSensorInstance::~KUKASeamTechonLaserSensorInstance(){
    if (this->pBackend != nullptr) delete this->pBackend;
    if (this->pHmi != nullptr) delete this->pHmi;
}

QWidget* KUKASeamTechonLaserSensorInstance::getUiHandle(){
    if(this->pHmi != nullptr){
        return this->pHmi;
    }
    else{
        return nullptr;
    }
}

void KUKASeamTechonLaserSensorInstance::RegisiterBackendtoHmi(){
        this->pHmi->getBackendhandle(this->pBackend);
}

void KUKASeamTechonLaserSensorInstance::task_uifast_UiDataUpdate(){
    if(this->pHmi != nullptr){
        this->pHmi->UiDataUpdate();
    }
}
void KUKASeamTechonLaserSensorInstance::task_uifast_LaserDataScopeUpdate(){
    if(this->pHmi != nullptr){
        this->pHmi->LaserSensorDataScopeViewUpdate();
    }
}

void  KUKASeamTechonLaserSensorInstance::task_mainloop_toRobotKRLReceiveLoopRun(){
    if(this->pBackend != nullptr){
        this->pBackend->toRobotKRLReceiveLoopRun();
    }
}
void  KUKASeamTechonLaserSensorInstance::task_mainloop_toRobotKRLSendLoopRun(){
    if(this->pBackend != nullptr){
        this->pBackend->toRobotKRLSendLoopRun();
    }
}
void  KUKASeamTechonLaserSensorInstance::task_mainloop_toLaserSensorReceive(){
    if(this->pBackend != nullptr){
        this->pBackend->frLaserSensorReceive();
    }
}
void  KUKASeamTechonLaserSensorInstance::task_mainloop_toLaserSensorSend(){
    if(this->pBackend != nullptr){
        this->pBackend->toLaserSensorSend();
    }
}
void  KUKASeamTechonLaserSensorInstance::task_mainloop_SeamTechTCPThreadLoopRun(){
    if(this->pBackend != nullptr){
        this->pBackend->SeamTechTCPThreadLoopRun();
    }
}

void  KUKASeamTechonLaserSensorInstance::task_kukaloop_SeamTechUDPThreadLoopRun(){
    if(this->pBackend != nullptr){
        this->pBackend->SeamTechUDPThreadLoopRun();
    }
}

void  KUKASeamTechonLaserSensorInstance::task_com_RemoteDataRecv(QByteArray Data){
    if(this->pHmi != nullptr){
        this->pHmi->RemoteDataRecv(Data);
    }
}
void  KUKASeamTechonLaserSensorInstance::task_com_RemoteDataSend(QByteArray& Data){
    if(this->pHmi != nullptr){
        this->pHmi->RemoteDataSend(Data);
    }
}

void  KUKASeamTechonLaserSensorInstance::task_mainloop_LaserSensorDataSave(){
    if(this->pBackend != nullptr){
        this->pBackend->LaserSensorDataSave();
    }
}
